﻿using Roton.Memory;
using Roton.ZZT;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Roton.Wrapper
{
    /// <summary>
    /// Adapts IString to a Segment object.
    /// </summary>
    class ByteStringWrapper : IString
    {
        private int offset;
        private Segment segment;

        public ByteStringWrapper(int offset, Segment segment)
        {
            this.offset = offset;
            this.segment = segment;
        }

        public override string ToString()
        {
            return Value;
        }

        public byte this[int index]
        {
            get
            {
                return (byte)segment.Read8(offset + index);
            }
            set
            {
                segment.Write8(offset + index, value);
            }
        }

        public ByteString Value
        {
            get
            {
                return segment.ReadString(offset);
            }
            set
            {
                segment.WriteString(offset, value);
            }
        }
    }
}
